<?php
class Experience extends Frank implements iFrank
{
	//properties
	protected $description;
	protected $dateIn;
	protected $dateOut;
	protected $place;
	protected $website;
	protected $jobTitle;
	protected $accomplishments;
	protected $image;
	
	//Getters
	public function description(){return $this->description;}
	public function dateIn(){return $this->dateIn;}
	public function dateOut(){return $this->dateOut;}
	public function place(){return $this->place;}
	public function website(){return $this->website;}
	public function jobTitle(){return $this->jobTitle;}
	public function accomplishments(){return $this->accomplishments;}
	public function image(){return $this->image;}
	
	public function __construct ($id, $name, $description, $dateIn, $dateOut, $place, $website, $jobTitle, $accomplishments, $image){
		$this->id = $id;
		$this->name = $name;
		$this->description = $description;
		$this->dateIn = new datetime($dateIn);
        if($dateOut != null)
            $this->dateOut = new datetime($dateOut);
		$this->place = $place;
		$this->website = $website;
		$this->jobTitle = $jobTitle;
		$this->accomplishments = $accomplishments;
		$this->image = $image;
	}
        
	public static function getObject($row){
		return new Experience($row["id"], $row["name"], $row["description"], $row["date_in"], $row["date_out"], $row["place"], $row["website"], $row["job_title"], $row["accomplishments"], $row["image_name"]);
	}
        
        public static function getAll($toArray = false, $fields = null, $query = null, $db = null) {
            $query = "select * from `".EXPERIENCE_TABLE."` order by display_order";
            return parent::getAll($toArray, $fields, $query, $db);
        }
    
        public static function getById($id, $toArray = false, $fields = null, $query = null, $db = null){
            $query = 'select * from `' . EXPERIENCE_TABLE . '` where id = '.$id;
            return parent::getById($id, $toArray, $fields, $query, $db);
        }
	
	public static function getAllForSkillId($skillId, $db){
		$query = 'select * '
			.'from  `'.EXPERIENCE_TABLE.'` '
			.'join `'.SKILL_EXPERIENCE_TABLE.'` ON `'.EXPERIENCE_TABLE.'`.id = `'.SKILL_EXPERIENCE_TABLE.'`.experience_id '
			.'where `'.SKILL_EXPERIENCE_TABLE.'`.skill_id = '.$skillId;
		return Experience::get($query, $db);
	}
	
	public static function search($q){
		$query = "select *, match (name, description, job_title, accomplishments) against ('+($q)' IN BOOLEAN MODE) AS score"
					."from  `frank.experience`"
					."where match (name, description, job_title, accomplishments) against ('+($q)' IN BOOLEAN MODE)"
					."ORDER BY score DESC";
		return Experience::get($query);
	}
}
?>